<template>
	<view class="meinfo">
		<view class="header">
			<view class="name" @click="opr1">
				<text class="touxiang">头像</text>
				<image :src="userdata.userimg"></image>
			</view>
			<view class="name" @click="opr2">
				<text class="touxiang">呢称</text>
				<text class="necheng">{{userdata.username}}</text>
			</view>
			<view class="name">
				<text class="touxiang">生日</text>
				<text class="necheng">2000-01-01</text>
			</view>
			<view class="name">
				<text class="touxiang">性别</text>
				<text class="necheng">{{userdata.gender==1?'男':'女'}}</text>
			</view>
			
		</view>
		<view class="footer">
			<text @click="clearall">清除缓存</text>
			<text @click="delme">退出登录</text>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				userdata:{}
			}
		},
		onShow(){
			// console.log("onshow")
			let userdata1=uni.getStorageSync("userinfo")
			// console.log(userdata1)
			this.userdata=userdata1
		},
		methods:{
			//关于头像的操作
			opr1(){
				uni.showActionSheet({
					itemList:["查看头像","从相册上传头像"],
					success:res=>{
						let index=res.tapIndex
						let faceurl=this.userdata.userimg
						let faceurllist=[this.userdata.userimg]
						if(index==0){	
							uni.previewImage({
								urls:faceurllist,
								current:faceurl
							})
						}else if(index==1){
							uni.chooseImage({
							    count: 1, //默认9
							    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
							    sourceType: ['album'], //从相册选择
							    success: function (res) {
									uni.navigateTo({
										url:`/pages/me/headerimg?url=${res.tempFilePaths[0]}`
									})
							       
							    }
							});
							
						}
					}
				})
			},
			
			opr2(){
				uni.navigateTo({
					url:`/pages/me/username?username=${this.userdata.username}`
				})
			},
			//清除缓存
			clearall(){
				uni.clearStorageSync()
				uni.showToast({
					title:"清理成功",
					mask:false,
					duration:2000
				})
				
			},
			// 退出登录/
			delme(){
				uni.clearStorageSync()
				uni.switchTab({
					url:"/pages/me/index"
				})
				uni.showToast({
					title:"清理成功",
					mask:false,
					duration:2000
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.meinfo{
		min-height: 100vh;
		width: 100vw;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: center;
		.header{
			width: 100vw;
		.name{
			height: 120upx;
			line-height: 120upx;
			border-bottom: 1px solid #ccc;
			width: 100%;
			padding: 0 40upx;
			display: flex;
			justify-content: space-between;
			image{
				width: 100upx;
				height: 100upx;
				border-radius: 50%;
			}
			
		}	
		}
		.footer{
			text{
				border-top:1px solid #ccc;
				display: block;
				text-align: center;
				width: 100vw;
				height: 90upx;
				line-height: 90upx;
				border-radius:5upx ;
			}
		}
	}
</style>
